package com.hzjy.manage.controller;

import java.util.List;

import com.hzjy.manage.service.HzjyUserService;
import com.hzjy.manage.vo.HzjyUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzjy.common.annotation.Log;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.enums.BusinessType;
import com.hzjy.common.utils.poi.ExcelUtil;
import com.hzjy.common.core.page.TableDataInfo;

/**
 * 前端-用户Controller
 *
 * @author hzjy
 * @date 2020-08-07
 */
@RestController
@RequestMapping("/manage/hzjy_user")
public class HzjyUserController extends BaseController
{
    @Autowired
    private HzjyUserService hzjyUserService;

    /**
     * 查询前端-用户列表
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:list')")
    @GetMapping("/list")
    public TableDataInfo list(HzjyUser hzjyUser)
    {
        startPage();
        List<HzjyUser> list = hzjyUserService.selectHzjyUserList(hzjyUser);
        return getDataTable(list);
    }

    /**
     * 导出前端-用户列表
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:export')")
    @Log(title = "前端-用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HzjyUser hzjyUser)
    {
        List<HzjyUser> list = hzjyUserService.selectHzjyUserList(hzjyUser);
        ExcelUtil<HzjyUser> util = new ExcelUtil<HzjyUser>(HzjyUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取前端-用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(hzjyUserService.selectHzjyUserById(userId));
    }

    /**
     * 新增前端-用户
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:add')")
    @Log(title = "前端-用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HzjyUser hzjyUser)
    {
        return toAjax(hzjyUserService.insertHzjyUser(hzjyUser));
    }

    /**
     * 修改前端-用户
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:edit')")
    @Log(title = "前端-用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HzjyUser hzjyUser)
    {
        return toAjax(hzjyUserService.updateHzjyUser(hzjyUser));
    }

    /**
     * 删除前端-用户
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:remove')")
    @Log(title = "前端-用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(hzjyUserService.deleteHzjyUserByIds(userIds));
    }
    /**
     * 修改用户状态(0-正常，1封禁)
     */
    @PreAuthorize("@ss.hasPermi('manage:hzjy_user:edit')")
    @Log(title = "前端-用户", businessType = BusinessType.UPDATE)
    @PostMapping("/changeState")
    public AjaxResult changeState(@RequestBody HzjyUser hzjyUser){
        return toAjax(hzjyUserService.updateHzjyUserState(hzjyUser));
    }

    /**
     * 修改用户状态(0-正常，1封禁)
     */
    /*@PreAuthorize("@ss.hasPermi('manage:hzjy_user:userList')")
    @PostMapping("/selectUserList")
    public AjaxResult selectUserList(@RequestBody HzjyUser hzjyUser){
        return toAjax(hzjyUserService.updateHzjyUserState(hzjyUser));
    }*/
}
